

/**
 * @param {number[][]} points
 * @return {number}
 */
var findMinArrowShots1 = function(points) {
    if (points.length <= 1) return points.length;

    // 按照区间的左边界升序排列
    points.sort((a, b) => a[0] - b[0]);

    let res = 1;
    // 将第一个区间设置为可射区间
    let range = [points[0][0], points[0][1]];

    for (let i = 1; i < points.length; i++) {
        const curr = points[i];
        if (curr[0] <= range[1]) {
            range[0] = Math.max(range[0], curr[0]);
            range[1] = Math.min(range[1], curr[1]);
        } else {
            res++;
            range[0] = curr[0];
            range[1] = curr[1];
        }
    }

    return res;
};





/**
 * @param {number[][]} points
 * @return {number}
 */
var findMinArrowShots = function(points) {
    if (points.length <= 1) return points.length;

    // 按照区间的右边界升序排列
    points.sort((a, b) => a[1] - b[1]);

    let res = 1;
    let pos = points[0][1];
    for (let i = 1; i < points.length; i++) {
        const curr = points[i];
        if (curr[0] > pos) {
            res++;
            pos = curr[1];
        }
    }

    return res;
};